<template>
  <el-dialog
    width="700px"
    :title="$t('文案代做流程')"
    destroy-on-close
    append-to-body
    :visible.sync="show"
    :before-close="cancel"
  >
    <template #title>
      <div style="display: flex">
        <div style="flex: 2">
          <el-tooltip effect="dark" placement="top-start">
            <div slot="content">
              <p>{{ $t('选择添加到文案代做申请列表-->批量付款后开始制作-->完成后验收') }}</p>
              <p>{{ $t('一套文案包含"标题","五点描述","详细描述","6张产品图"') }}</p>
              <p>{{ $t('验收后会添加到自己的sku模板中，可以自行修改其中信息') }}</p>
            </div>
            <i style="cursor: pointer" class="el-icon-info"></i>
          </el-tooltip>
          {{ $t('文案代做流程') }}
        </div>
        <div style="color: red; flex: 3">{{ $t('组合去组合列表上申请') }}</div>
      </div>
    </template>

    <el-alert
      v-if="total > 0"
      :title="`请注意，sku：${formData.skuNo}以前申请过${total}套模板了`"
      type="warning"
      effect="dark"
    >
    </el-alert>
    <section class="wenan-info">
      <div class="wenan-info-left">
        <div style="font-size: 16px">{{ formData.skuNo }}</div>
        <div>
          <el-image
            @click="$viewImage(formData.imgUrl)"
            style="width: 150px; height: 150px; cursor: pointer"
            fit="contain"
            :src="formData.imgUrl"
          />
        </div>
      </div>
      <div class="wenan-info-right">
        <div>
          <span>价格</span>
          <el-input disabled style="width: 200px; margin: 10px; margin-right: 5px" v-model="form.unitPrice">
            <i slot="suffix">JPY</i>
          </el-input>
          <span>/套</span>
        </div>
        <div>
          <span>申请数量</span>
          <el-input-number style="width: 200px; margin: 10px" v-model="form.num" controls-position="right" :min="1" />
          <span>套</span>
        </div>
      </div>
    </section>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleSubmit" type="primary" v-hasPermi="['distribution:skuTempProxyApply:add']">
        {{ $t('确定') }}
      </el-button>
      <el-button @click="cancel">{{ $t('关闭') }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getApplyNumBySkuId, add } from '@/api/distribution/sku/SellerSku'
import { useDict } from '@/utils/useDict'

export default {
  activated() {
    this.$nextTick(() => this.$refs['TableRef']?.doLayout())
  },
  props: {
    /**
     * formData
     */
    formData: {
      type: Object,
      default: () => ({}),
    },
    /**
     * 控制显示隐藏
     */
    show: {
      type: Boolean,
      required: true,
      default: false,
    },
  },
  data() {
    return {
      total: 0,
      sku_temp_proxy_list: [],
      form: {
        unitPrice: '',
        num: '',
      },
      // 查询参数
      queryParams: {},
    }
  },
  computed: {},
  watch: {
    show: function (newValue) {
      this.form.num = 1
      if (newValue) {
        this.getList()
        useDict('sku_temp_proxy').then(({ sku_temp_proxy }) => {
          this.sku_temp_proxy_list = sku_temp_proxy
          this.form.unitPrice = sku_temp_proxy[0]?.dictLabel
        })
      }
    },
  },
  methods: {
    handleSubmit() {
      const data = {
        ...this.form,
        skuId: this.formData.skuId,
        skuNo: this.formData.skuNo,
      }
      add(data).then((res) => {
        const { code, data, msg } = res
        if (code === 200) {
          this.$message({ type: 'success', message: msg })
          this.$emit('getList')
          this.cancel()
        }
      })
    },
    getList() {
      getApplyNumBySkuId({ skuId: this.formData.skuId }).then((res) => {
        this.total = res.data
      })
    },

    cancel() {
      this.$emit('update:show', false)
    },
  },
}
</script>
<style scoped lang="scss">
.wenan-info {
  display: flex;
  margin-top: 20px;
  &-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  &-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    margin-right: 30px;
    ::v-deep .el-input__suffix {
      display: flex;
      align-items: center;
    }
  }
}
</style>
